/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.business.data;

import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
 *
 * @author alabuschagne
 */
@MappedSuperclass
public class GenericData implements Serializable, Comparable
{

    private static final long serialVersionUID = 1L;
    protected Long id;
    protected String name = "";
    protected String description = "";
    private boolean processed = false;
    protected boolean readyToChange = false;
    protected boolean dirty = false;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GenericData))
        {
            return false;
        }
        GenericData other = (GenericData) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        if(name != null)
        {
            return name;
        }
        else if (description != null)
        {
            return description;
        }
        else
        {
            return "[id=" + id + "]";
        }
    }

    /**
     * @return the name
     */
    public String getName()
    {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * @return the description
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description)
    {
        this.description = description;
    }

    public boolean check(GenericData other)
    {
        if(other == null)
        {
            return false;
        }
        if(name.compareTo(other.getName()) != 0)
        {
            return false;
        }
        else if(description.compareTo(other.getDescription()) != 0)
        {
            return false;
        }
        return true;
    }

    /**
     * @return the processed
     */
    @Transient
    public boolean isProcessed()
    {
        return processed;
    }

    /**
     * @param processed the processed to set
     */
    public void setProcessed(boolean processed)
    {
        this.processed = processed;
    }

    @Override
    public int compareTo(Object o)
    {
        if(o instanceof GenericData)
        {
            GenericData gd = (GenericData)o;
            return getName().compareTo(gd.getName());
        }
        return -1;
    }

    /**
     * @return the readyToChange
     */
    @Transient
    public boolean isReadyToChange()
    {
        return readyToChange;
    }

    /**
     * @param readyToChange the readyToChange to set
     */
    public void setReadyToChange(boolean readyToChange)
    {
        this.readyToChange = readyToChange;
    }

    /**
     * @return the dirty
     */
    @Transient
    public boolean isDirty()
    {
        return dirty;
    }

    /**
     * @param dirty the dirty to set
     */
    public void setDirty(boolean dirty)
    {
        this.dirty = dirty;
    }

    //abstract public void resetDirty();

}
